package cn.lasse.springframework.aop.framework.adapter;

import cn.lasse.springframework.aop.MethodBeforeAdvice;
import lombok.NoArgsConstructor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

@NoArgsConstructor
public class MethodBeforeAdviceInterceptor implements MethodInterceptor {
    private MethodBeforeAdvice beforeAdvice;

    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
        this.beforeAdvice = advice;
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        this.beforeAdvice.before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return invocation.proceed();
    }
}
